package ogdkp.actions;

import ogdkp.dialog.AddLootDialog;
import ogdkp.om.Loot;
import ogdkp.om.Player;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.TreeViewer;

public class EditLootAction extends Action {

	private final Loot loot;

	private final TreeViewer viewer;

	public EditLootAction(final Loot loot, final TreeViewer viewer) {
		setText("Edit");
		this.loot = loot;
		this.viewer = viewer;
	}

	@Override
	public void run() {
		final AddLootDialog dialog = new AddLootDialog(viewer.getControl().getShell(), (Player) loot.getParent(), null);
		dialog.setName(loot.getName());
		dialog.setValue(loot.getCost() + "");
		if (dialog.open() == dialog.OK) {
			loot.setName(dialog.getName());
			loot.setCost(Integer.parseInt(dialog.getValue()));
			viewer.refresh();
		}

	}

}
